//
//  WriteFamilyViewController.m
//  安好
//
//  Created by lianchuang on 14-11-17.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "WriteFamilyViewController.h"
#define CellLineColor [UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1]

#define IPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

@interface WriteFamilyViewController ()<UITextFieldDelegate>

@end

@implementation WriteFamilyViewController

- (void)viewDidLoad {
    self.view.backgroundColor = [ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    [super viewDidLoad];
    [self makeNavBar];
    [self loadData];
    [self makeView];
    
}
/**
 *  视图加载viewDidLoad执行完之后执行这个方法
 *
 *  @param animated 弹出键盘
 */
-(void)viewDidAppear:(BOOL)animated
{
    [self.WriteTextField becomeFirstResponder];
}
#pragma mark - 导航设置
-(void)makeNavBar
{
    self.navigationItem.title = self.navBarTitle;
    //贴图
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backBtnClicked)];
    backBtnImg.tintColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = backBtnImg;
}
/**
 *  返回 -- 代理传值
 */
-(void)backBtnClicked
{
    //在这里把空格切割掉
    NSArray * subArr = [self.WriteTextField.text componentsSeparatedByString:@" "];
    NSMutableString * getString = [NSMutableString stringWithCapacity:0];
    for (NSString * str in subArr) {
        [getString appendString:str];
    }
    
    [self.delegate reloadTableViewSelectedCellPlaceholeder:getString];
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - 数据加载--textfield显示传过来的提示文本
-(void)loadData
{
    self.WriteTextField.placeholder = self.textFieldPlaceholder;
    self.WriteTextField.returnKeyType = UIReturnKeyDone;
    self.WriteTextField.text = self.textString;
}
#pragma mark - 修改视图
-(void)makeView
{
    
    self.WriteBackView.backgroundColor = [UIColor whiteColor];
    self.WriteBackView.width = kScreenWidth;
    self.WriteTopLineView.backgroundColor = CellLineColor;
    self.WriteTopLineView.height = 0.3;
    self.WriteTopLineView.width = kScreenWidth;
    
    self.WriteTextField.width = kScreenWidth-30;
    self.WriteBottomLineView.backgroundColor = CellLineColor;
    self.WriteBottomLineView.frame = CGRectMake(0, 43.5, kScreenWidth, 0.5);
    self.WriteTextField.delegate = self;
    self.WriteTextField.clearButtonMode = UITextFieldViewModeAlways;
    if (IPhone6Plus) {
        self.WriteTextField.left = 20;
        self.WriteTextField.width = kScreenWidth-40;
        self.WriteBackView.height = 53;
        self.WriteBottomLineView.frame = CGRectMake(0, 52.5, kScreenWidth, 0.5);
        self.WriteTextField.height = 36;
        self.WriteTextField.top = (self.WriteBackView.height - self.WriteTextField.height)/2.0;
        self.WriteTextField.font = [UIFont systemFontOfSize:15];
        
        
    }
    if ([self.navigationItem.title isEqualToString:@"手机号"]|| [self.navigationItem.title isEqualToString:@"身份证"]) {
        self.WriteTextField.keyboardType =  UIKeyboardTypeNumbersAndPunctuation;
    }
    
    
}

#pragma mark - textField的代理方法
/**
 *  点击键盘 return(“确认”) 触发方法--
 *
 *  @param textField 取消第一响应，键盘收起。返回到上一个页面
 *
 *  @return
 */
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    [self backBtnClicked];
    return YES;
}

@end
